package flag

import (
	"gin_study_blog/common"
	"gin_study_blog/models"
	"gin_study_blog/plugins/log_stash"
)

func MakeMigrations() {
	var err error
	//common.DB.SetupJoinTable(&models.UserModel{}, "CollectsModels", &models.UserCollectsModel{})
	common.DB.SetupJoinTable(&models.MenuModel{}, "Banners", &models.MenuBannerModel{})
	// 生成表的表结构
	err = common.DB.Set("gorm:table_options", "ENGINE=InnoDB").
		AutoMigrate(
			&models.BannerModel{},
			&models.TagModel{},
			&models.MessageModel{},
			&models.AdvertModel{},
			&models.UserModel{},
			&models.CommentModel{},
			&models.UserCollectsModel{},
			//&models.ArticleModel{},
			&models.MenuModel{},
			&models.MenuBannerModel{},
			&models.FeedBackModel{},
			&models.LoginDataModel{},
			&models.ChatModel{},
			&log_stash.LogStashModel{},
		)
	if err != nil {
		common.Log.Error("生成数据库表结构失败")
		return
	}
	common.Log.Info("生成数据库表结构成功")
}
